package openHome.dao;

import java.sql.Statement;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;


public class MySQLConexionBD {

    private static MySQLConexionBD instance;

     

    public static MySQLConexionBD getInstance(){
        if(instance == null)
            instance = new MySQLConexionBD();

        return instance;
    }

    public Connection getConnection()     {
        Connection cn = null;
        Properties prop;
        try{
            prop = new Properties();
            prop.load(MySQLConexionBD.class.getResourceAsStream("ConexionBD.properties"));

            //prop.getProperty("driver");
            Class.forName(prop.getProperty("driver"));
            String URL = prop.getProperty("url");
            String USER = prop.getProperty("user");
            String PASS = prop.getProperty("pass");
            
            cn = DriverManager.getConnection(URL, USER, PASS);

        }catch(IOException ex ) {
            ex.printStackTrace(System.out);
        }catch(SQLException ex) {
             ex.printStackTrace(System.out);
        }catch(Exception ex) {
              ex.printStackTrace(System.out);
        }

        return cn;
    }

    public void close(Connection cn) {
        try {
            if(cn != null) {
                cn.close();
            }
        }catch(Exception ex){
           
        }
    }

    public void close(Statement stm) {
        try {
            if(stm != null) {
                stm.close();
            }
        }catch(Exception ex){
           
        }
    }

    public void close(ResultSet rs) {
        try {
            if(rs != null) {
                rs.close();
            }
        }catch(Exception ex){
            
        }
    }
}

